{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为___none_____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为___30,4_____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为__3______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为__97______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(  F  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(  F  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(  T  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(  T  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入字符串\"124587\"\n",
      "Counter({'\"': 2, '1': 1, '2': 1, '4': 1, '5': 1, '8': 1, '7': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "a = input(\"请输入字符串\")\n",
    "b = Counter(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：\"112254548\"\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('8', 9)]\n"
     ]
    }
   ],
   "source": [
    "positions = [(ch, index) for index, ch in enumerate(text) if text.index(ch)==text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：“451245127”\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('“', 0), ('4', 5), ('5', 6), ('1', 7), ('2', 8), ('7', 9), ('”', 10)]\n"
     ]
    }
   ],
   "source": [
    "positions =[(ch,index) for index,ch in enumerate(text)\n",
    "if index == text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表：[{54,45},{45,54}]\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator import __or__\n",
    "x = eval(input('请输入包含若干集合的列表：'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{45, 54}\n"
     ]
    }
   ],
   "source": [
    "print(reduce(__or__,x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串\"12345654321\"\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Yes\n"
     ]
    }
   ],
   "source": [
    "x = s[::-1]\n",
    "if s == x:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.()里的值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.remove()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.[6,7,9,11]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6.{},键和值，键"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7.items(),keys(),values()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "8. [\"dict(zip(a,b))\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "9. b=a[::3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "10.5 for i in range(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "11.不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = ['789546123','asdfgh','693741852']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['789546123', 'asdfgh', '693741852']\n"
     ]
    }
   ],
   "source": [
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "def prime(x):                       \n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output=filter(prime,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "14,为了不破坏原本列表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[78, 17, 39, 27, 1, 92, 45, 91, 90, 13, 11, 62, 2, 6, 64, 63, 1, 59, 15, 38, 62, 50, 69, 88, 72, 43, 14, 99, 17, 35, 62, 84, 35, 13, 92, 86, 85, 57, 90, 97, 60, 15, 46, 45, 94, 42, 42, 11, 94, 77, 67, 74, 19, 62, 96, 12, 7, 68, 59, 10, 33, 33, 71, 68, 27, 83, 27, 25, 6, 4, 65, 29, 45, 28, 18, 18, 53, 74, 7, 54, 81, 13, 40, 38, 96, 74, 60, 76, 17, 52, 5, 62, 99, 1, 62, 85, 34, 2, 16, 92, 30, 63, 19, 24, 10, 99, 90, 16, 49, 74, 87, 19, 58, 50, 58, 45, 37, 98, 44, 75, 77, 71, 93, 2, 40, 6, 10, 80, 44, 28, 54, 91, 85, 100, 37, 78, 0, 78, 16, 21, 60, 89, 58, 21, 25, 38, 58, 70, 10, 11, 33, 62, 50, 61, 14, 40, 61, 19, 30, 68, 68, 91, 94, 57, 100, 19, 32, 92, 13, 44, 66, 87, 41, 15, 23, 38, 96, 46, 72, 39, 15, 49, 20, 98, 18, 85, 52, 83, 15, 29, 0, 84, 21, 58, 79, 10, 30, 93, 49, 7, 47, 71, 53, 19, 46, 19, 44, 5, 15, 81, 93, 67, 15, 61, 26, 9, 23, 75, 63, 19, 28, 93, 72, 28, 56, 9, 85, 60, 25, 19, 99, 39, 17, 14, 26, 37, 86, 67, 4, 82, 34, 76, 77, 70, 11, 82, 41, 18, 58, 70, 69, 26, 42, 5, 28, 66, 16, 87, 93, 53, 72, 61, 90, 63, 39, 11, 36, 10, 0, 39, 50, 62, 61, 87, 47, 71, 94, 53, 16, 76, 87, 49, 48, 13, 85, 8, 42, 76, 97, 40, 62, 18, 60, 24, 64, 81, 56, 7, 22, 55, 19, 45, 71, 47, 78, 75, 7, 52, 26, 36, 6, 96, 36, 24, 40, 77, 38, 80, 54, 83, 23, 75, 86, 66, 34, 67, 70, 83, 77, 89, 37, 44, 82, 86, 71, 36, 28, 11, 38, 24, 94, 53, 21, 18, 28, 80, 90, 78, 24, 88, 62, 80, 17, 80, 11, 74, 99, 50, 24, 51, 45, 5, 49, 49, 31, 99, 11, 77, 69, 18, 66, 51, 19, 56, 93, 64, 36, 67, 43, 71, 62, 68, 92, 76, 15, 81, 19, 26, 12, 25, 81, 13, 61, 29, 41, 93, 45, 52, 85, 68, 77, 36, 1, 20, 96, 22, 68, 78, 97, 9, 85, 31, 54, 85, 13, 23, 36, 21, 48, 15, 3, 31, 53, 24, 39, 81, 35, 41, 43, 62, 52, 81, 95, 38, 1, 51, 61, 18, 11, 8, 30, 14, 62, 16, 91, 54, 68, 28, 87, 23, 20, 24, 7, 94, 42, 23, 34, 76, 87, 4, 97, 14, 27, 96, 30, 43, 98, 1, 43, 79, 66, 76, 29, 4, 35, 80, 14, 21, 53, 97, 43, 49, 54, 29, 6, 69, 6, 53, 92, 84, 38, 87, 57, 95, 97, 8, 34, 18, 89, 84, 38, 78, 4, 74, 45, 40, 15, 76, 97, 40, 56, 46, 50, 76, 94, 10, 69, 47, 81, 94, 71, 32, 6, 11, 46, 76, 94, 81, 49, 40, 80, 17, 78, 85, 40, 40, 40, 39, 60, 73, 22, 62, 42, 4, 26, 31, 28, 9, 13, 1, 99, 10, 38, 86, 27, 12, 60, 15, 90, 79, 10, 7, 31, 35, 45, 69, 52, 14, 68, 14, 28, 81, 89, 6, 45, 39, 6, 26, 29, 90, 27, 85, 88, 19, 96, 100, 79, 90, 10, 35, 78, 3, 29, 64, 6, 5, 57, 70, 14, 48, 95, 30, 33, 24, 35, 74, 36, 96, 34, 91, 38, 70, 63, 65, 51, 32, 37, 83, 62, 98, 51, 65, 90, 6, 78, 69, 1, 2, 79, 20, 54, 62, 69, 16, 12, 83, 70, 65, 59, 38, 40, 58, 31, 48, 37, 73, 6, 24, 97, 49, 70, 45, 13, 91, 54, 5, 64, 83, 58, 81, 94, 18, 58, 60, 10, 66, 42, 34, 63, 24, 27, 7, 62, 85, 40, 3, 82, 77, 53, 12, 54, 67, 39, 18, 34, 72, 20, 51, 60, 95, 0, 42, 64, 33, 48, 63, 28, 53, 53, 8, 72, 2, 90, 27, 26, 74, 77, 55, 20, 83, 67, 89, 71, 86, 4, 27, 93, 61, 72, 82, 83, 42, 32, 89, 15, 53, 40, 25, 40, 23, 83, 80, 100, 15, 17, 30, 10, 19, 68, 10, 60, 51, 10, 44, 39, 93, 70, 44, 11, 77, 92, 84, 99, 39, 94, 33, 87, 69, 75, 77, 52, 19, 97, 77, 80, 2, 14, 6, 7, 23, 70, 90, 41, 89, 55, 64, 84, 9, 68, 52, 15, 42, 63, 49, 17, 70, 16, 69, 100, 82, 72, 48, 41, 44, 42, 24, 4, 85, 16, 99, 18, 57, 84, 97, 87, 0, 9, 98, 1, 26, 52, 56, 6, 59, 63, 77, 17, 68, 31, 13, 50, 92, 61, 94, 77, 25, 49, 43, 65, 97, 89, 42, 63, 77, 38, 28, 91, 49, 68, 78, 22, 44, 42, 54, 9, 20, 28, 16, 87, 3, 67, 44, 29, 20, 25, 42, 51, 3, 61, 18, 20, 96, 0, 89, 75, 80, 92, 81, 96, 4, 36, 23, 3, 96, 11, 73, 94, 45, 64, 7, 93, 98, 96, 53, 40, 61, 78, 97, 15, 32, 67, 27, 9, 24, 77, 5, 20, 9, 7, 92, 66, 37, 33, 33, 84, 79, 47, 85, 88, 29, 20, 10, 69, 87, 27, 33, 17, 30, 85, 40, 38, 82, 35, 17, 86, 48, 19, 25, 18, 82, 20, 49, 25, 77, 51, 12, 52, 29, 93, 26, 47, 92, 30, 44, 7, 27, 26, 46, 32, 37, 55, 92, 23, 32, 7, 19, 62, 14, 7, 96, 75, 12, 35, 75, 59, 61, 80, 45, 54, 66, 68, 51, 68, 35, 78, 1, 30, 24, 98, 23, 9, 33, 44, 94, 21, 41, 68, 61, 48, 3, 42, 19, 66, 50, 84, 76, 67, 75, 51, 97]\n",
      "78 : 13\n",
      "17 : 11\n",
      "39 : 11\n",
      "27 : 12\n",
      "1 : 10\n",
      "92 : 12\n",
      "45 : 13\n",
      "91 : 7\n",
      "90 : 11\n",
      "13 : 10\n",
      "11 : 12\n",
      "62 : 18\n",
      "2 : 6\n",
      "6 : 14\n",
      "64 : 8\n",
      "63 : 10\n",
      "1 : 10\n",
      "59 : 5\n",
      "15 : 15\n",
      "38 : 14\n",
      "62 : 18\n",
      "50 : 8\n",
      "69 : 11\n",
      "88 : 4\n",
      "72 : 8\n",
      "43 : 7\n",
      "14 : 11\n",
      "99 : 9\n",
      "17 : 11\n",
      "35 : 10\n",
      "62 : 18\n",
      "84 : 9\n",
      "35 : 10\n",
      "13 : 10\n",
      "92 : 12\n",
      "86 : 7\n",
      "85 : 15\n",
      "57 : 5\n",
      "90 : 11\n",
      "97 : 13\n",
      "60 : 10\n",
      "15 : 15\n",
      "46 : 6\n",
      "45 : 13\n",
      "94 : 14\n",
      "42 : 15\n",
      "42 : 15\n",
      "11 : 12\n",
      "94 : 14\n",
      "77 : 17\n",
      "67 : 10\n",
      "74 : 8\n",
      "19 : 18\n",
      "62 : 18\n",
      "96 : 13\n",
      "12 : 7\n",
      "7 : 14\n",
      "68 : 16\n",
      "59 : 5\n",
      "10 : 15\n",
      "33 : 10\n",
      "33 : 10\n",
      "71 : 9\n",
      "68 : 16\n",
      "27 : 12\n",
      "83 : 10\n",
      "27 : 12\n",
      "25 : 9\n",
      "6 : 14\n",
      "4 : 9\n",
      "65 : 5\n",
      "29 : 10\n",
      "45 : 13\n",
      "28 : 13\n",
      "18 : 14\n",
      "18 : 14\n",
      "53 : 13\n",
      "74 : 8\n",
      "7 : 14\n",
      "54 : 11\n",
      "81 : 12\n",
      "13 : 10\n",
      "40 : 17\n",
      "38 : 14\n",
      "96 : 13\n",
      "74 : 8\n",
      "60 : 10\n",
      "76 : 11\n",
      "17 : 11\n",
      "52 : 10\n",
      "5 : 7\n",
      "62 : 18\n",
      "99 : 9\n",
      "1 : 10\n",
      "62 : 18\n",
      "85 : 15\n",
      "34 : 8\n",
      "2 : 6\n",
      "16 : 10\n",
      "92 : 12\n",
      "30 : 10\n",
      "63 : 10\n",
      "19 : 18\n",
      "24 : 14\n",
      "10 : 15\n",
      "99 : 9\n",
      "90 : 11\n",
      "16 : 10\n",
      "49 : 13\n",
      "74 : 8\n",
      "87 : 12\n",
      "19 : 18\n",
      "58 : 9\n",
      "50 : 8\n",
      "58 : 9\n",
      "45 : 13\n",
      "37 : 8\n",
      "98 : 7\n",
      "44 : 12\n",
      "75 : 9\n",
      "77 : 17\n",
      "71 : 9\n",
      "93 : 11\n",
      "2 : 6\n",
      "40 : 17\n",
      "6 : 14\n",
      "10 : 15\n",
      "80 : 11\n",
      "44 : 12\n",
      "28 : 13\n",
      "54 : 11\n",
      "91 : 7\n",
      "85 : 15\n",
      "100 : 5\n",
      "37 : 8\n",
      "78 : 13\n",
      "0 : 6\n",
      "78 : 13\n",
      "16 : 10\n",
      "21 : 7\n",
      "60 : 10\n",
      "89 : 9\n",
      "58 : 9\n",
      "21 : 7\n",
      "25 : 9\n",
      "38 : 14\n",
      "58 : 9\n",
      "70 : 11\n",
      "10 : 15\n",
      "11 : 12\n",
      "33 : 10\n",
      "62 : 18\n",
      "50 : 8\n",
      "61 : 13\n",
      "14 : 11\n",
      "40 : 17\n",
      "61 : 13\n",
      "19 : 18\n",
      "30 : 10\n",
      "68 : 16\n",
      "68 : 16\n",
      "91 : 7\n",
      "94 : 14\n",
      "57 : 5\n",
      "100 : 5\n",
      "19 : 18\n",
      "32 : 7\n",
      "92 : 12\n",
      "13 : 10\n",
      "44 : 12\n",
      "66 : 9\n",
      "87 : 12\n",
      "41 : 7\n",
      "15 : 15\n",
      "23 : 11\n",
      "38 : 14\n",
      "96 : 13\n",
      "46 : 6\n",
      "72 : 8\n",
      "39 : 11\n",
      "15 : 15\n",
      "49 : 13\n",
      "20 : 12\n",
      "98 : 7\n",
      "18 : 14\n",
      "85 : 15\n",
      "52 : 10\n",
      "83 : 10\n",
      "15 : 15\n",
      "29 : 10\n",
      "0 : 6\n",
      "84 : 9\n",
      "21 : 7\n",
      "58 : 9\n",
      "79 : 6\n",
      "10 : 15\n",
      "30 : 10\n",
      "93 : 11\n",
      "49 : 13\n",
      "7 : 14\n",
      "47 : 6\n",
      "71 : 9\n",
      "53 : 13\n",
      "19 : 18\n",
      "46 : 6\n",
      "19 : 18\n",
      "44 : 12\n",
      "5 : 7\n",
      "15 : 15\n",
      "81 : 12\n",
      "93 : 11\n",
      "67 : 10\n",
      "15 : 15\n",
      "61 : 13\n",
      "26 : 11\n",
      "9 : 10\n",
      "23 : 11\n",
      "75 : 9\n",
      "63 : 10\n",
      "19 : 18\n",
      "28 : 13\n",
      "93 : 11\n",
      "72 : 8\n",
      "28 : 13\n",
      "56 : 5\n",
      "9 : 10\n",
      "85 : 15\n",
      "60 : 10\n",
      "25 : 9\n",
      "19 : 18\n",
      "99 : 9\n",
      "39 : 11\n",
      "17 : 11\n",
      "14 : 11\n",
      "26 : 11\n",
      "37 : 8\n",
      "86 : 7\n",
      "67 : 10\n",
      "4 : 9\n",
      "82 : 8\n",
      "34 : 8\n",
      "76 : 11\n",
      "77 : 17\n",
      "70 : 11\n",
      "11 : 12\n",
      "82 : 8\n",
      "41 : 7\n",
      "18 : 14\n",
      "58 : 9\n",
      "70 : 11\n",
      "69 : 11\n",
      "26 : 11\n",
      "42 : 15\n",
      "5 : 7\n",
      "28 : 13\n",
      "66 : 9\n",
      "16 : 10\n",
      "87 : 12\n",
      "93 : 11\n",
      "53 : 13\n",
      "72 : 8\n",
      "61 : 13\n",
      "90 : 11\n",
      "63 : 10\n",
      "39 : 11\n",
      "11 : 12\n",
      "36 : 9\n",
      "10 : 15\n",
      "0 : 6\n",
      "39 : 11\n",
      "50 : 8\n",
      "62 : 18\n",
      "61 : 13\n",
      "87 : 12\n",
      "47 : 6\n",
      "71 : 9\n",
      "94 : 14\n",
      "53 : 13\n",
      "16 : 10\n",
      "76 : 11\n",
      "87 : 12\n",
      "49 : 13\n",
      "48 : 8\n",
      "13 : 10\n",
      "85 : 15\n",
      "8 : 4\n",
      "42 : 15\n",
      "76 : 11\n",
      "97 : 13\n",
      "40 : 17\n",
      "62 : 18\n",
      "18 : 14\n",
      "60 : 10\n",
      "24 : 14\n",
      "64 : 8\n",
      "81 : 12\n",
      "56 : 5\n",
      "7 : 14\n",
      "22 : 4\n",
      "55 : 4\n",
      "19 : 18\n",
      "45 : 13\n",
      "71 : 9\n",
      "47 : 6\n",
      "78 : 13\n",
      "75 : 9\n",
      "7 : 14\n",
      "52 : 10\n",
      "26 : 11\n",
      "36 : 9\n",
      "6 : 14\n",
      "96 : 13\n",
      "36 : 9\n",
      "24 : 14\n",
      "40 : 17\n",
      "77 : 17\n",
      "38 : 14\n",
      "80 : 11\n",
      "54 : 11\n",
      "83 : 10\n",
      "23 : 11\n",
      "75 : 9\n",
      "86 : 7\n",
      "66 : 9\n",
      "34 : 8\n",
      "67 : 10\n",
      "70 : 11\n",
      "83 : 10\n",
      "77 : 17\n",
      "89 : 9\n",
      "37 : 8\n",
      "44 : 12\n",
      "82 : 8\n",
      "86 : 7\n",
      "71 : 9\n",
      "36 : 9\n",
      "28 : 13\n",
      "11 : 12\n",
      "38 : 14\n",
      "24 : 14\n",
      "94 : 14\n",
      "53 : 13\n",
      "21 : 7\n",
      "18 : 14\n",
      "28 : 13\n",
      "80 : 11\n",
      "90 : 11\n",
      "78 : 13\n",
      "24 : 14\n",
      "88 : 4\n",
      "62 : 18\n",
      "80 : 11\n",
      "17 : 11\n",
      "80 : 11\n",
      "11 : 12\n",
      "74 : 8\n",
      "99 : 9\n",
      "50 : 8\n",
      "24 : 14\n",
      "51 : 11\n",
      "45 : 13\n",
      "5 : 7\n",
      "49 : 13\n",
      "49 : 13\n",
      "31 : 7\n",
      "99 : 9\n",
      "11 : 12\n",
      "77 : 17\n",
      "69 : 11\n",
      "18 : 14\n",
      "66 : 9\n",
      "51 : 11\n",
      "19 : 18\n",
      "56 : 5\n",
      "93 : 11\n",
      "64 : 8\n",
      "36 : 9\n",
      "67 : 10\n",
      "43 : 7\n",
      "71 : 9\n",
      "62 : 18\n",
      "68 : 16\n",
      "92 : 12\n",
      "76 : 11\n",
      "15 : 15\n",
      "81 : 12\n",
      "19 : 18\n",
      "26 : 11\n",
      "12 : 7\n",
      "25 : 9\n",
      "81 : 12\n",
      "13 : 10\n",
      "61 : 13\n",
      "29 : 10\n",
      "41 : 7\n",
      "93 : 11\n",
      "45 : 13\n",
      "52 : 10\n",
      "85 : 15\n",
      "68 : 16\n",
      "77 : 17\n",
      "36 : 9\n",
      "1 : 10\n",
      "20 : 12\n",
      "96 : 13\n",
      "22 : 4\n",
      "68 : 16\n",
      "78 : 13\n",
      "97 : 13\n",
      "9 : 10\n",
      "85 : 15\n",
      "31 : 7\n",
      "54 : 11\n",
      "85 : 15\n",
      "13 : 10\n",
      "23 : 11\n",
      "36 : 9\n",
      "21 : 7\n",
      "48 : 8\n",
      "15 : 15\n",
      "3 : 7\n",
      "31 : 7\n",
      "53 : 13\n",
      "24 : 14\n",
      "39 : 11\n",
      "81 : 12\n",
      "35 : 10\n",
      "41 : 7\n",
      "43 : 7\n",
      "62 : 18\n",
      "52 : 10\n",
      "81 : 12\n",
      "95 : 4\n",
      "38 : 14\n",
      "1 : 10\n",
      "51 : 11\n",
      "61 : 13\n",
      "18 : 14\n",
      "11 : 12\n",
      "8 : 4\n",
      "30 : 10\n",
      "14 : 11\n",
      "62 : 18\n",
      "16 : 10\n",
      "91 : 7\n",
      "54 : 11\n",
      "68 : 16\n",
      "28 : 13\n",
      "87 : 12\n",
      "23 : 11\n",
      "20 : 12\n",
      "24 : 14\n",
      "7 : 14\n",
      "94 : 14\n",
      "42 : 15\n",
      "23 : 11\n",
      "34 : 8\n",
      "76 : 11\n",
      "87 : 12\n",
      "4 : 9\n",
      "97 : 13\n",
      "14 : 11\n",
      "27 : 12\n",
      "96 : 13\n",
      "30 : 10\n",
      "43 : 7\n",
      "98 : 7\n",
      "1 : 10\n",
      "43 : 7\n",
      "79 : 6\n",
      "66 : 9\n",
      "76 : 11\n",
      "29 : 10\n",
      "4 : 9\n",
      "35 : 10\n",
      "80 : 11\n",
      "14 : 11\n",
      "21 : 7\n",
      "53 : 13\n",
      "97 : 13\n",
      "43 : 7\n",
      "49 : 13\n",
      "54 : 11\n",
      "29 : 10\n",
      "6 : 14\n",
      "69 : 11\n",
      "6 : 14\n",
      "53 : 13\n",
      "92 : 12\n",
      "84 : 9\n",
      "38 : 14\n",
      "87 : 12\n",
      "57 : 5\n",
      "95 : 4\n",
      "97 : 13\n",
      "8 : 4\n",
      "34 : 8\n",
      "18 : 14\n",
      "89 : 9\n",
      "84 : 9\n",
      "38 : 14\n",
      "78 : 13\n",
      "4 : 9\n",
      "74 : 8\n",
      "45 : 13\n",
      "40 : 17\n",
      "15 : 15\n",
      "76 : 11\n",
      "97 : 13\n",
      "40 : 17\n",
      "56 : 5\n",
      "46 : 6\n",
      "50 : 8\n",
      "76 : 11\n",
      "94 : 14\n",
      "10 : 15\n",
      "69 : 11\n",
      "47 : 6\n",
      "81 : 12\n",
      "94 : 14\n",
      "71 : 9\n",
      "32 : 7\n",
      "6 : 14\n",
      "11 : 12\n",
      "46 : 6\n",
      "76 : 11\n",
      "94 : 14\n",
      "81 : 12\n",
      "49 : 13\n",
      "40 : 17\n",
      "80 : 11\n",
      "17 : 11\n",
      "78 : 13\n",
      "85 : 15\n",
      "40 : 17\n",
      "40 : 17\n",
      "40 : 17\n",
      "39 : 11\n",
      "60 : 10\n",
      "73 : 3\n",
      "22 : 4\n",
      "62 : 18\n",
      "42 : 15\n",
      "4 : 9\n",
      "26 : 11\n",
      "31 : 7\n",
      "28 : 13\n",
      "9 : 10\n",
      "13 : 10\n",
      "1 : 10\n",
      "99 : 9\n",
      "10 : 15\n",
      "38 : 14\n",
      "86 : 7\n",
      "27 : 12\n",
      "12 : 7\n",
      "60 : 10\n",
      "15 : 15\n",
      "90 : 11\n",
      "79 : 6\n",
      "10 : 15\n",
      "7 : 14\n",
      "31 : 7\n",
      "35 : 10\n",
      "45 : 13\n",
      "69 : 11\n",
      "52 : 10\n",
      "14 : 11\n",
      "68 : 16\n",
      "14 : 11\n",
      "28 : 13\n",
      "81 : 12\n",
      "89 : 9\n",
      "6 : 14\n",
      "45 : 13\n",
      "39 : 11\n",
      "6 : 14\n",
      "26 : 11\n",
      "29 : 10\n",
      "90 : 11\n",
      "27 : 12\n",
      "85 : 15\n",
      "88 : 4\n",
      "19 : 18\n",
      "96 : 13\n",
      "100 : 5\n",
      "79 : 6\n",
      "90 : 11\n",
      "10 : 15\n",
      "35 : 10\n",
      "78 : 13\n",
      "3 : 7\n",
      "29 : 10\n",
      "64 : 8\n",
      "6 : 14\n",
      "5 : 7\n",
      "57 : 5\n",
      "70 : 11\n",
      "14 : 11\n",
      "48 : 8\n",
      "95 : 4\n",
      "30 : 10\n",
      "33 : 10\n",
      "24 : 14\n",
      "35 : 10\n",
      "74 : 8\n",
      "36 : 9\n",
      "96 : 13\n",
      "34 : 8\n",
      "91 : 7\n",
      "38 : 14\n",
      "70 : 11\n",
      "63 : 10\n",
      "65 : 5\n",
      "51 : 11\n",
      "32 : 7\n",
      "37 : 8\n",
      "83 : 10\n",
      "62 : 18\n",
      "98 : 7\n",
      "51 : 11\n",
      "65 : 5\n",
      "90 : 11\n",
      "6 : 14\n",
      "78 : 13\n",
      "69 : 11\n",
      "1 : 10\n",
      "2 : 6\n",
      "79 : 6\n",
      "20 : 12\n",
      "54 : 11\n",
      "62 : 18\n",
      "69 : 11\n",
      "16 : 10\n",
      "12 : 7\n",
      "83 : 10\n",
      "70 : 11\n",
      "65 : 5\n",
      "59 : 5\n",
      "38 : 14\n",
      "40 : 17\n",
      "58 : 9\n",
      "31 : 7\n",
      "48 : 8\n",
      "37 : 8\n",
      "73 : 3\n",
      "6 : 14\n",
      "24 : 14\n",
      "97 : 13\n",
      "49 : 13\n",
      "70 : 11\n",
      "45 : 13\n",
      "13 : 10\n",
      "91 : 7\n",
      "54 : 11\n",
      "5 : 7\n",
      "64 : 8\n",
      "83 : 10\n",
      "58 : 9\n",
      "81 : 12\n",
      "94 : 14\n",
      "18 : 14\n",
      "58 : 9\n",
      "60 : 10\n",
      "10 : 15\n",
      "66 : 9\n",
      "42 : 15\n",
      "34 : 8\n",
      "63 : 10\n",
      "24 : 14\n",
      "27 : 12\n",
      "7 : 14\n",
      "62 : 18\n",
      "85 : 15\n",
      "40 : 17\n",
      "3 : 7\n",
      "82 : 8\n",
      "77 : 17\n",
      "53 : 13\n",
      "12 : 7\n",
      "54 : 11\n",
      "67 : 10\n",
      "39 : 11\n",
      "18 : 14\n",
      "34 : 8\n",
      "72 : 8\n",
      "20 : 12\n",
      "51 : 11\n",
      "60 : 10\n",
      "95 : 4\n",
      "0 : 6\n",
      "42 : 15\n",
      "64 : 8\n",
      "33 : 10\n",
      "48 : 8\n",
      "63 : 10\n",
      "28 : 13\n",
      "53 : 13\n",
      "53 : 13\n",
      "8 : 4\n",
      "72 : 8\n",
      "2 : 6\n",
      "90 : 11\n",
      "27 : 12\n",
      "26 : 11\n",
      "74 : 8\n",
      "77 : 17\n",
      "55 : 4\n",
      "20 : 12\n",
      "83 : 10\n",
      "67 : 10\n",
      "89 : 9\n",
      "71 : 9\n",
      "86 : 7\n",
      "4 : 9\n",
      "27 : 12\n",
      "93 : 11\n",
      "61 : 13\n",
      "72 : 8\n",
      "82 : 8\n",
      "83 : 10\n",
      "42 : 15\n",
      "32 : 7\n",
      "89 : 9\n",
      "15 : 15\n",
      "53 : 13\n",
      "40 : 17\n",
      "25 : 9\n",
      "40 : 17\n",
      "23 : 11\n",
      "83 : 10\n",
      "80 : 11\n",
      "100 : 5\n",
      "15 : 15\n",
      "17 : 11\n",
      "30 : 10\n",
      "10 : 15\n",
      "19 : 18\n",
      "68 : 16\n",
      "10 : 15\n",
      "60 : 10\n",
      "51 : 11\n",
      "10 : 15\n",
      "44 : 12\n",
      "39 : 11\n",
      "93 : 11\n",
      "70 : 11\n",
      "44 : 12\n",
      "11 : 12\n",
      "77 : 17\n",
      "92 : 12\n",
      "84 : 9\n",
      "99 : 9\n",
      "39 : 11\n",
      "94 : 14\n",
      "33 : 10\n",
      "87 : 12\n",
      "69 : 11\n",
      "75 : 9\n",
      "77 : 17\n",
      "52 : 10\n",
      "19 : 18\n",
      "97 : 13\n",
      "77 : 17\n",
      "80 : 11\n",
      "2 : 6\n",
      "14 : 11\n",
      "6 : 14\n",
      "7 : 14\n",
      "23 : 11\n",
      "70 : 11\n",
      "90 : 11\n",
      "41 : 7\n",
      "89 : 9\n",
      "55 : 4\n",
      "64 : 8\n",
      "84 : 9\n",
      "9 : 10\n",
      "68 : 16\n",
      "52 : 10\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15 : 15\n",
      "42 : 15\n",
      "63 : 10\n",
      "49 : 13\n",
      "17 : 11\n",
      "70 : 11\n",
      "16 : 10\n",
      "69 : 11\n",
      "100 : 5\n",
      "82 : 8\n",
      "72 : 8\n",
      "48 : 8\n",
      "41 : 7\n",
      "44 : 12\n",
      "42 : 15\n",
      "24 : 14\n",
      "4 : 9\n",
      "85 : 15\n",
      "16 : 10\n",
      "99 : 9\n",
      "18 : 14\n",
      "57 : 5\n",
      "84 : 9\n",
      "97 : 13\n",
      "87 : 12\n",
      "0 : 6\n",
      "9 : 10\n",
      "98 : 7\n",
      "1 : 10\n",
      "26 : 11\n",
      "52 : 10\n",
      "56 : 5\n",
      "6 : 14\n",
      "59 : 5\n",
      "63 : 10\n",
      "77 : 17\n",
      "17 : 11\n",
      "68 : 16\n",
      "31 : 7\n",
      "13 : 10\n",
      "50 : 8\n",
      "92 : 12\n",
      "61 : 13\n",
      "94 : 14\n",
      "77 : 17\n",
      "25 : 9\n",
      "49 : 13\n",
      "43 : 7\n",
      "65 : 5\n",
      "97 : 13\n",
      "89 : 9\n",
      "42 : 15\n",
      "63 : 10\n",
      "77 : 17\n",
      "38 : 14\n",
      "28 : 13\n",
      "91 : 7\n",
      "49 : 13\n",
      "68 : 16\n",
      "78 : 13\n",
      "22 : 4\n",
      "44 : 12\n",
      "42 : 15\n",
      "54 : 11\n",
      "9 : 10\n",
      "20 : 12\n",
      "28 : 13\n",
      "16 : 10\n",
      "87 : 12\n",
      "3 : 7\n",
      "67 : 10\n",
      "44 : 12\n",
      "29 : 10\n",
      "20 : 12\n",
      "25 : 9\n",
      "42 : 15\n",
      "51 : 11\n",
      "3 : 7\n",
      "61 : 13\n",
      "18 : 14\n",
      "20 : 12\n",
      "96 : 13\n",
      "0 : 6\n",
      "89 : 9\n",
      "75 : 9\n",
      "80 : 11\n",
      "92 : 12\n",
      "81 : 12\n",
      "96 : 13\n",
      "4 : 9\n",
      "36 : 9\n",
      "23 : 11\n",
      "3 : 7\n",
      "96 : 13\n",
      "11 : 12\n",
      "73 : 3\n",
      "94 : 14\n",
      "45 : 13\n",
      "64 : 8\n",
      "7 : 14\n",
      "93 : 11\n",
      "98 : 7\n",
      "96 : 13\n",
      "53 : 13\n",
      "40 : 17\n",
      "61 : 13\n",
      "78 : 13\n",
      "97 : 13\n",
      "15 : 15\n",
      "32 : 7\n",
      "67 : 10\n",
      "27 : 12\n",
      "9 : 10\n",
      "24 : 14\n",
      "77 : 17\n",
      "5 : 7\n",
      "20 : 12\n",
      "9 : 10\n",
      "7 : 14\n",
      "92 : 12\n",
      "66 : 9\n",
      "37 : 8\n",
      "33 : 10\n",
      "33 : 10\n",
      "84 : 9\n",
      "79 : 6\n",
      "47 : 6\n",
      "85 : 15\n",
      "88 : 4\n",
      "29 : 10\n",
      "20 : 12\n",
      "10 : 15\n",
      "69 : 11\n",
      "87 : 12\n",
      "27 : 12\n",
      "33 : 10\n",
      "17 : 11\n",
      "30 : 10\n",
      "85 : 15\n",
      "40 : 17\n",
      "38 : 14\n",
      "82 : 8\n",
      "35 : 10\n",
      "17 : 11\n",
      "86 : 7\n",
      "48 : 8\n",
      "19 : 18\n",
      "25 : 9\n",
      "18 : 14\n",
      "82 : 8\n",
      "20 : 12\n",
      "49 : 13\n",
      "25 : 9\n",
      "77 : 17\n",
      "51 : 11\n",
      "12 : 7\n",
      "52 : 10\n",
      "29 : 10\n",
      "93 : 11\n",
      "26 : 11\n",
      "47 : 6\n",
      "92 : 12\n",
      "30 : 10\n",
      "44 : 12\n",
      "7 : 14\n",
      "27 : 12\n",
      "26 : 11\n",
      "46 : 6\n",
      "32 : 7\n",
      "37 : 8\n",
      "55 : 4\n",
      "92 : 12\n",
      "23 : 11\n",
      "32 : 7\n",
      "7 : 14\n",
      "19 : 18\n",
      "62 : 18\n",
      "14 : 11\n",
      "7 : 14\n",
      "96 : 13\n",
      "75 : 9\n",
      "12 : 7\n",
      "35 : 10\n",
      "75 : 9\n",
      "59 : 5\n",
      "61 : 13\n",
      "80 : 11\n",
      "45 : 13\n",
      "54 : 11\n",
      "66 : 9\n",
      "68 : 16\n",
      "51 : 11\n",
      "68 : 16\n",
      "35 : 10\n",
      "78 : 13\n",
      "1 : 10\n",
      "30 : 10\n",
      "24 : 14\n",
      "98 : 7\n",
      "23 : 11\n",
      "9 : 10\n",
      "33 : 10\n",
      "44 : 12\n",
      "94 : 14\n",
      "21 : 7\n",
      "41 : 7\n",
      "68 : 16\n",
      "61 : 13\n",
      "48 : 8\n",
      "3 : 7\n",
      "42 : 15\n",
      "19 : 18\n",
      "66 : 9\n",
      "50 : 8\n",
      "84 : 9\n",
      "76 : 11\n",
      "67 : 10\n",
      "75 : 9\n",
      "51 : 11\n",
      "97 : 13\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "16"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your nameliu jing wennnn\n"
     ]
    }
   ],
   "source": [
    "d = {'LI':'1','XI':'2','GUA':3}\n",
    "a = input('input your name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9,\n",
       " 98,\n",
       " 88,\n",
       " 88,\n",
       " 62,\n",
       " 46,\n",
       " 42,\n",
       " 36,\n",
       " 68,\n",
       " 100,\n",
       " 79,\n",
       " 19,\n",
       " 43,\n",
       " 15,\n",
       " 84,\n",
       " 92,\n",
       " 12,\n",
       " 79,\n",
       " 95,\n",
       " 94]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9, 36, 42, 46, 62, 68, 88, 88, 98, 100, 95, 94, 92, 84, 79, 79, 43, 19, 15, 12]\n"
     ]
    }
   ],
   "source": [
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
